<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>


<link rel="stylesheet" type="text/css" href="../bootstarp-3.3.7/css/bootstrap.min.css"/>
<script src="../assets/js/jquery-2.0.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" type="text/css" href="../bootstarp-table-1.11.1/bootstrap-table.min.css"/>
<script src="../bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
  



<script type="text/javascript">
	
	
	
		
	
	$(function() {
		//添加下拉框拿值
		
		$.ajax({
			type : "post",
			url : "../dw/queryStandard_unit.lgg",
			success : function(data) {
				$.each(data, function(index, row) {
					$("#catery3").append("<option value='" + row.catery + "'>" + row.catery + "</option>")
				});
			    }
		        })
		

		//模糊查询后刷新表格
		$("#cha").click(function(){
       		$("#table").bootstrapTable("refresh");
		})
		
		
		$("#table").bootstrapTable(
						{
							url : "../dw/dwdas.lgg",
							pagination : true,
							pageSize : 3,
							queryParams: queryParams,
							columns : [{
										field : 'unitid',
										title : '单位id',
										align : 'center'
									},{
										field : 'name',
										title : '单位名称', 
										align : 'center'
									},{
										field : 'catery',
										title : '单位类别',
										align : 'center'
									},{
										field : 'description',
										title : '单位描述',
										align : 'center'
									},{	
										title : '操作',
										align : 'center',
										formatter : function(value,row,index) {
											return '<button onclick="shanchu('+ row.unitid + ')" class="btn btn-info glyphicon glyphicon-trash"></button>  <button onclick="dwxuigai('+ row.unitid + ')" class="btn btn-danger glyphicon glyphicon-edit""></button>'
											 
										}   
									   }]							
						              })
		
		
		//下拉列表拿值
		$.ajax({
			type : "post",
			url : "../dw/dwdas.lgg",
			success : function(data) {
				$.each(data, function(index, row) {
					$("#catery2").append("<option value='" + row.catery + "'>" + row.catery + "</option>")
				});
			    }
		        })
		
		         })
	
	              //添加
	            function dwadd() {	 
	            	$.ajax({
	            		type:"post",
	            		url:"../dw/dwinsert.lgg",
	            		data:$("#myformss").serialize(),
	            		success:function (data) {
	            			alert(data)
	            	//隐藏
	            			$("#myModal").modal("hide")
	            	//刷新
	            			$("#table").bootstrap('refresh')
	            		}
	            	});	 
	            }
	
	
	            /* 删除 */
		         function shanchu(unitid) {
			            $.ajax({
			             url : "../dw/dwdel.lgg",
				         data : "unitid=" + unitid,
				         type : "post",
				 //刷新
			        	success : function(data) {			        		
				     	$("table").bootstrapTable("refresh");
				       }
			           })
                       }
		         
         
	  //单位修改展示模态框
                function dwxuigai(unitid){             
                	$("#myModal01").modal('show');
                	//拿值
                	$.ajax({
                		type:"post",
                		url:"../dw/dwxuigai.lgg",
                		data:"unitid=" + unitid,
                	
                		success:function (data) {
                			$("#unitid2").val(data.unitid);
                			$("#name2").val(data.name);
                			$("#description2").val(data.description);
                			$("#catery2").val(data.catery);
                		}
                	});
                }	         
		   
		       //修改
             function update() {
                $.ajax({
					type: "post",
					url: "../dw/dwupdate.lgg",
					data:$("#myformss1").serialize(),
					success: function(data) {		
						$("#myModal01").modal("hide")
						$("#table1").bootstrapTable('refresh')
					}
				});
				
              }    
		//模糊查询         
	function queryParams(){
		return {
			'name':$("#name").val(),
			'catery':$("#catery").val()
		}
	}
		         
		         
		         
		         
		         
		         
		         
		         
		         
</script>
</head>
 <body>
 <div align="center">
<form id="mo" class="form-inline">
<input type="text" name="name" class="form-control" style="width: 150px;" placeholder="请输入单位名称" id="name"/>
<input type="text" name="catery" class="form-control" style="width: 150px;" placeholder="请输入单位类别" id="catery"/>
<button type="button" id="cha" class="btn btn-default glyphicon glyphicon-search"></button>
<button type="button" class="btn btn-primary glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal" onclick="tj()"></button>
	
</form>
</div>
<br />
<!-- Button trigger modal -->
	
     <table class="table table-responsive" id="table"></table>

	<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document"> 
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">标准单位基本信息</h4>
						
				</div>
				<div class="modal-body">

                     <!--表单 -->
					<form class="form-horizontal" id="myformss">
					
					<div class="form-group">
							<label for="inputEmail3" class="col-sm-2 control-label">编号</label>
							<div class="col-sm-10">
								<input type="email" class="form-control" name="unitid" placeholder="请输入单位编号">
							</div>
						</div>

						<div class="form-group">
							<label for="inputPassword3" class="col-sm-2 control-label">单位名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="name" placeholder="请输入单位名称">
							</div>
						</div>
					
						<div class="form-group">
							<label for="inputEmail3" class="col-sm-2 control-label">单位描述</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="description" placeholder="请输入单位描述">
							</div>
						</div>

						<div class="form-group">
							<label for="inputPassword3" class="col-sm-2 control-label">单位类别</label>
							<div class="col-sm-10">
								<select class="form-control" id="catery3" name="catery">
									<option value="-1">请选择</option>
								</select>
							</div>
						</div>

					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" id="btn" onclick="dwadd()"></button>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>





<!-- 修改 -->
 <table class="table table-responsive" id="table1"></table>


	<div class="modal fade" id="myModal01" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document"> 
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">标准单位基本信息</h4>
						
				</div>
				<div class="modal-body">

                     <!--表单 -->
					<form class="form-horizontal" id="myformss1">
					
					<div class="form-group">
							<label for="inputEmail3" class="col-sm-2 control-label">编号</label>
							<div class="col-sm-10">
								<input type="email"  class="form-control" id="unitid2" name="unitid" placeholder="请输入单位编号">
							</div>
						</div>

						<div class="form-group">
							<label for="inputPassword3" class="col-sm-2 control-label">单位名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="name2" name="name" placeholder="请输入单位名称">
							</div>
						</div>
					
						<div class="form-group">
							<label for="inputEmail3" class="col-sm-2 control-label">单位类别</label>
							<div class="col-sm-10">		
							<select class="form-control" id="catery2" name="catery"></select>
							</div>
						</div>

						<div class="form-group">
							<label for="inputPassword3" class="col-sm-2 control-label">单位描述</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="description2" name="description" placeholder="请输入单位描述">
							</div>
						</div>

					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" id="btn" onclick="update()"></button>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>



</body>
</html>